﻿function renameTag(TheUrl, TheId, TagName, AfterFunc) {
    var Thename = window.prompt("New name of the tag?", TagName);
    if (!Thename)
        return;
    
    

    $.ajax({
        type: "POST",
        url: TheUrl,
        data: { id: TheId, name: Thename },
        datatype: "JSON",
        success: function (returndata) {
            if (returndata.ok) {
                if(AfterFunc)
                    AfterFunc(Thename);                
            }
            else {
                //this is an error from the server
                window.alert(' error : ' + returndata.message);
            }

        }
    }
        );
}
function Search(urlSearch, replaceValue) {
    var vnd = window.prompt("What to search for ?", "");
    if (!vnd)
        return;
    var url = urlSearch.replace(replaceValue, vnd);

    window.location = url;
}
function deleteTag(TheUrl, TheId, TagName, AfterFunc) {
    var Thename = window.confirm("Are you sure to delete "+ TagName);
    if (!Thename)
        return;


    $.ajax({
        type: "POST",
        url: TheUrl,
        data: { id: TheId, name: Thename },
        datatype: "JSON",
        success: function (returndata) {
            if (returndata.ok) {
                if (AfterFunc)
                    AfterFunc(Thename);
            }
            else {
                //this is an error from the server
                window.alert(' error : ' + returndata.message);
            }

        }
    }
        );
}


function Delete(TheUrl, TheId, name, AfterFunc) {
    if (!window.confirm("Are you sure to delete " + name))
        return;
    
    $.ajax({
        type: "POST",
        url: TheUrl,
        data: { id: TheId },
        datatype: "JSON",

        success: function (returndata) {
            if (returndata.ok) {
                AfterFunc();
            }
            else {
                //this is an error from the server
                window.alert(' error : ' + returndata.message);
            }

        }
    }
        );

}